# -*- coding: utf-8 -*-

# 引入os模块，用来解析文件路径
import os

# 引入QgsRasterLayer和QgsVectorLayer类，用来加载栅格和矢量图层
from qgis.core import (
    QgsSymbol,
    QgsSymbolLayer,
    QgsSingleSymbolRenderer,
    QgsMarkerSymbol,
    QgsLineSymbol,
    QgsFillSymbol,
    QgsSimpleFillSymbolLayer
)

from PyQt5.QtGui import QColor

class SymbolTools:
    """
    符号工具类
    """
    @staticmethod
    def get_symbol(single_symbol_renderer: QgsSingleSymbolRenderer) -> QgsSymbol:
        """
        获取符号表
        :param single_symbol_renderer: 单符号渲染器
        :return: QgsSymbol
        """
        return single_symbol_renderer.symbol()
    
    @staticmethod
    def set_symbol(single_symbol_renderer: QgsSingleSymbolRenderer,symbol: QgsSymbol):
        """
        设置符号表
        :param single_symbol_renderer: 单符号渲染器
        :param symbol: QgsSymbol
        """
        single_symbol_renderer.setSymbol(symbol)
    
    @staticmethod
    def get_marker_symbol(marker_symbol: QgsSymbol)->QgsMarkerSymbol:
        """
        获取点符号
        :param marker_symbol: QgsSymbol
        :return: QgsMarkerSymbol
        """
        return marker_symbol
    
    @staticmethod
    def get_line_symbol(line_symbol: QgsSymbol)->QgsLineSymbol:
        """
        获取线符号
        :param line_symbol: QgsSymbol
        :return: QgsLineSymbol
        """
        return line_symbol

    @staticmethod
    def get_fill_symbol(fill_symbol: QgsSymbol)->QgsFillSymbol:
        """
        获取填充符号
        :param fill_symbol: QgsSymbol
        :return: QgsFillSymbol
        """
        return fill_symbol
    
    @staticmethod
    def get_simple_fill_symbol(fill_symbol:QgsFillSymbol) -> QgsSimpleFillSymbolLayer:
        """
        获取填充符号
        :param fill_symbol: QgsFillSymbol
        :return: QgsSimpleFillSymbolLayer
        """
        return fill_symbol.symbolLayer(0)
    
    @staticmethod
    def get_simple_fill_symbol(symbollayer:QgsSymbolLayer) -> QgsSimpleFillSymbolLayer:
        """
        获取填充符号
        :param symbollayer: QgsSymbolLayer
        :return: QgsSimpleFillSymbolLayer
        """
        return symbollayer

    @staticmethod
    def get_marker_symbol(color:QColor,point_size:float,opacity:float) -> QgsMarkerSymbol:
        """
        获取点符号
        :param color: 颜色
        :param point_size: 点大小
        :param opacity: 透明度
        :return: QgsMarkerSymbol
        """
        marker = QgsMarkerSymbol()
        marker.setColor(color)
        marker.setSize(point_size)
        marker.setOpacity(opacity)
        return marker
    
    @staticmethod
    def get_line_symbol(color:QColor,width:float,opacity:float) -> QgsLineSymbol:
        """
        获取线符号
        :param color: 颜色
        :param width: 线宽
        :param opacity: 透明度
        :return: QgsLineSymbol
        """
        line_symbol = QgsLineSymbol()
        line_symbol.setColor(color)
        line_symbol.setWidth(width)
        line_symbol.setOpacity(opacity)
        return line_symbol
    
    @staticmethod
    def get_fill_symbol(fillcolor:QColor,strockcolor:QColor,strockwidth:float,opacity:float) -> QgsFillSymbol:
        """
        获取填充符号
        :param fillcolor: 填充颜色
        :param strockcolor: 边框颜色
        :param strockwidth: 边框宽度
        :param opacity: 透明度
        :return: QgsFillSymbol
        """
        fill_symbol = QgsFillSymbol()
        symbollayer = QgsSimpleFillSymbolLayer()
        symbollayer.setFillColor(fillcolor)
        symbollayer.setStrokeColor(strockcolor)
        symbollayer.setStrokeWidth(strockwidth)
        fill_symbol.changeSymbolLayer(0,symbollayer)
        fill_symbol.setOpacity(opacity)
        return fill_symbol
